package com.xbongbong.pro.enums.menu.enums;

import com.xbongbong.i18n.util.I18nMessageUtil;
import com.xbongbong.paas.enums.MenuTypeEnum;
import com.xbongbong.pro.enums.AccessLinkEnum;
import com.xbongbong.saas.enums.CompanyConfigEnum;
import com.xbongbong.saas.enums.XbbRefTypeEnum;
import lombok.Getter;

/**
 * @author feng.zheng
 * @version v1.0
 * @date 2019/11/28 21:15
 * @since v1.0
 */
@Getter
public enum AccordConfigMenuEnum {
    // 序列号查询
    SEQ_SEARCH(XbbRefTypeEnum.SEQ_SEARCH.getI18nName(), XbbRefTypeEnum.SEQ_SEARCH.getAlias(), XbbRefTypeEnum.SEQ_SEARCH.getCode(),
            AccessLinkEnum.SEQ_SEARCH,
            XbbRefTypeEnum.INVENTORY_MANAGEMENT.getAlias(), MenuTypeEnum.FORM.getType(), CompanyConfigEnum.ENABLE_SEQ_MANAGEMENT),
    BATCH_FLOW_BILL(XbbRefTypeEnum.BATCH_FLOW_BILL.getI18nName(), XbbRefTypeEnum.BATCH_FLOW_BILL.getAlias(), XbbRefTypeEnum.BATCH_FLOW_BILL.getCode(),
    AccessLinkEnum.BATCH_FLOW_BILL,
            XbbRefTypeEnum.INVENTORY_MANAGEMENT.getAlias(), MenuTypeEnum.FORM.getType(), CompanyConfigEnum.ENABLE_BATCH_SHELF_MANAGEMENT),
    // 库存流水查询
    STOCK_FLOW_BILL(XbbRefTypeEnum.STOCK_FLOW_BILL.getI18nName(), XbbRefTypeEnum.STOCK_FLOW_BILL.getAlias(), XbbRefTypeEnum.STOCK_FLOW_BILL.getCode(),
    AccessLinkEnum.STOCK_FLOW_BILL,
            XbbRefTypeEnum.INVENTORY_MANAGEMENT.getAlias(), MenuTypeEnum.FORM.getType(), CompanyConfigEnum.ENABLE_STOCK_FLOW_BILL),
    ;
    /**
     * saas应用标示解释
     */
    private String name;
    /**
     * saas应用标示
     * @see XbbRefTypeEnum
     */
    private String alias;
    /**
     * @see XbbRefTypeEnum
     */
    private Integer code;
    /**
     * 对应的链接
     */
    private AccessLinkEnum accessLinkEnum;

    /**
     * 父节点，如果没有父节点，则此值为空字符串
     */
    private String parent;
    /**
     * 类型
     * @see MenuTypeEnum
     */
    private Integer type;
    /**
     * 对应的公司级配置
     */
    private CompanyConfigEnum companyConfigEnum;

    AccordConfigMenuEnum(String name, String alias, Integer code, AccessLinkEnum accessLinkEnum, String parent, Integer type, CompanyConfigEnum companyConfigEnum){
        this.name = name;
        this.alias = alias;
        this.code = code;
        this.accessLinkEnum = accessLinkEnum;
        this.parent = parent;
        this.type = type;
        this.companyConfigEnum = companyConfigEnum;
    }

    public static AccordConfigMenuEnum getByAlias(String alias) {
        for (AccordConfigMenuEnum jxcMenuEnum: values()) {
            if(jxcMenuEnum.getAlias().equals(alias)) {
                return jxcMenuEnum;
            }
        }
        return null;
    }

    public static AccordConfigMenuEnum getByCompanyConfig(CompanyConfigEnum companyConfigEnum) {
        for (AccordConfigMenuEnum accordConfigMenuEnum: values()) {
            if(accordConfigMenuEnum.getCompanyConfigEnum().equals(companyConfigEnum)) {
                return accordConfigMenuEnum;
            }
        }
        return null;
    }

    public static AccordConfigMenuEnum getByCode(Integer code) {
        for(AccordConfigMenuEnum jxcMenuEnum: values()) {
            if(jxcMenuEnum.getCode().equals(code)){
                return jxcMenuEnum;
            }
        }
        return null;
    }

    public String getName() {
        return I18nMessageUtil.getMessage(name);
    }
}
